package day_2022_7_to_8.day48;

import java.util.*;

/**
 * @author haomin
 * @date 2022/08/19 17:55
 **/
public class Day34_4_Num71_SimplifyPath {
    class Solution {
        public String simplifyPath(String path) {
            String[] dir = path.split("/");
            Stack<String> stack = new Stack();
            for(int i = 0; i < dir.length;i++){
                if(dir[i].isEmpty() || dir[i].equals(".")) continue;
                if(dir[i].equals("..")){
                    if(!stack.isEmpty()) stack.pop();
                }else stack.push(dir[i]);
            }
            return "/" + String.join("/",stack);
        }
    }
}